export function isPhone(phone) {
    return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(phone);
}
export function toCustomerService() {
	uni.openCustomerServiceChat({
		extInfo: {url: 'https://work.weixin.qq.com/kfid/kfc0829c8a6dceb85fb'},
		corpId: 'wwce1cf5dd670d5d8c',
		fail: (res) => {
			console.log(res, "fail")
		},
		success:(res)=>{
			console.log(res, "success")
		}
	})
}

export function isValidChineseID(id) {  
    // 定义所有有效的地区码前两位  
    var validProvinces = ["11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41", "42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65"];  
      
    // 正则表达式部分  
    var reg = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;  
      
    // 提取地区码  
    var provinceCode = id.substring(0, 2);  
      
    // 检查地区码是否在有效列表中  
    if (validProvinces.includes(provinceCode)) {  
        return reg.test(id);  
    } else {  
        return false;  
    }  
}

// 银行卡正则
export  function isValidBankCard(cardNumber) {  
	// 验证银行卡号是否有效
	let reg = /^([1-9]{1})(\d{15}|\d{16}|\d{17}|\d{18})$/;
    return reg.test(cardNumber);
}

//  富文本格式化处理
export const  formatRichText = (html) => {
    let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
        match = match.replace(/style=\"[^\"]+\"/gi, '').replace(/style='[^']+'/gi, '').replace('style', 'styles');
        match = match.replace(/width=\"[^\"]+\"/gi, '').replace(/width='[^']+'/gi, '');
        match = match.replace(/height=\"[^\"]+\"/gi, '').replace(/height='[^']+'/gi, '');
        return match;
      });
      newContent = newContent.replace(/style=\"[^\"]+\"/gi,function(match,capture){
        match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
        return match;
      });
      newContent = newContent.replace(/&lt;br[^&gt;]*\/&gt;/gi, '');
      newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"');
      // newContent = newContent.replace(/<p[^>]*>/gi,function(match,capture){
      //   match = match.replace(/style=\"/gi, 'style="margin:20px 0;');
      //   return match;
      // });
      // newContent = newContent.replace(/<p>/gi, '<p style="margin: 20px 0;">');
      return newContent;
}

export const getImageType = (url) => {
  return url.substring(url.lastIndexOf('.') + 1, url.length).toLowerCase();
}

export const formatDate = (dateStr) => {  
    // 确保输入是8位数字  
    if (dateStr.length !== 8 || isNaN(dateStr)) {  
        return "长期";  
    }  
  
    // 提取年份、月份和日期  
    const year = dateStr.substring(0, 4);  
    const month = dateStr.substring(4, 6);  
    const day = dateStr.substring(6, 8);  
  
    // 使用模板字符串来组合并格式化日期  
    return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;  
}

export const isEmail = (email) => {
	return /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(email)
}

// 活动图标 type: 活动类型 1新人专享
import icon1 from '../static/images/activity-icon1.jpg';
import tag1 from '../static/images/activity-tag1.png';
export const activityImages = {
	1: {
		icon: icon1,
		tag: tag1,
		name: '新人专享'
	}
}